package cn.nawang.ebeim.ui.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;

import cn.nawang.ebeim.client.util.PropertiesConstants;
import cn.nawang.ebeim.client.util.PropertiesUtil;
import cn.nawang.ebeim.ui.bean.ConfigBean;

/**
 * @ClassName: ModifyConfigController
 * @Description: TODO
 * @author fanyb
 * @date Nov 12, 2015 5:49:12 PM
 * @version v1.0
 */
@RestController
public class ModifyConfigController {
  private static final Logger LOG = LoggerFactory.getLogger(ModifyConfigController.class);
  
  /**
   * 
   * @author: huanghj
   * @Description: 系统配置用户修改部分参数
   * @param @param config
   * @param @return
   * @return String
   * @date 2015年10月29日下午2:17:27
   *
   * @修改人
   * @修改日期
   */
  @RequestMapping(value = "modify/config", method = RequestMethod.POST)
  public String modifyConfig(ConfigBean config) {
    LOG.debug("modify/config {}",config);
    JSONObject json = new JSONObject();
    json.put("code", "500");
    Long writeLimit = Long.valueOf(config.getWriteLimit()) * 1000;
    Long readLimit = Long.valueOf(config.getReadLimit()) * 1000;

    try {
      PropertiesUtil.writeProperties(PropertiesConstants.WRITE_LIMIT, String.valueOf(writeLimit));
      PropertiesUtil.writeProperties(PropertiesConstants.READ_LIMIT, String.valueOf(readLimit));
      PropertiesUtil.writeProperties(PropertiesConstants.API_HOST, config.getServerIp());
      json.put("code", "200");
    } catch (Exception e) {
      e.printStackTrace();
    }

    return json.toString();

  }
}
